package org.xg.study.pd;

import org.xg.study.pd.event.EventManager;
import org.xg.study.pd.event.listener.MQEventListener;
import org.xg.study.pd.event.listener.MessageEventListener;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName LotteryService
 * @date 2021/9/17 10:15
 **/
public abstract class LotteryService {
    private EventManager eventManager;

    public LotteryService(){
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ,new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message,new MessageEventListener());
    }

    public LotteryResult draw(String uId){
        LotteryResult lotteryResult = doDraw(uId);
        //需要什么通知就调用什么方法
        eventManager.notify(EventManager.EventType.Message,lotteryResult);
        eventManager.notify(EventManager.EventType.MQ,lotteryResult);
        return lotteryResult;
    }

    protected abstract LotteryResult doDraw(String uId);
}
